package com.mobilebsc.datatype;

import org.json.JSONException;
import org.json.JSONObject;

public class GoalValueMap {

	private int id;
	private KPI kpi;
	private StrategicGoal strategicGoal;
	private double weight;
	
	/**
	 * Constructor for empty goal value maps
	 */
	public GoalValueMap() {
		this.id = -1;
		this.kpi = null;
		this.strategicGoal = null;
		this.weight = -1.0;
	}
	
	public GoalValueMap(int goalValueMapId, KPI kpi,
			StrategicGoal strategicGoal, double weight) {
		super();
		this.id = goalValueMapId;
		this.kpi = kpi;
		this.strategicGoal = strategicGoal;
		this.weight = weight;
	}
	
	/**
	 * Use for instancing a new GoalValueMap from UI: id is set by database
	 * @param kpi
	 * @param strategicGoal
	 * @param weight
	 */
	public GoalValueMap(KPI kpi, StrategicGoal strategicGoal, double weight) {
		super();
		this.kpi = kpi;
		this.strategicGoal = strategicGoal;
		this.weight = weight;
	}
	
	public int getGoalValueMapId() {
		return id;
	}
	
	public void setGoalValueMapId(int goalValueMapId) {
		this.id = goalValueMapId;
	}
	
	public KPI getKpi() {
		return kpi;
	}
	
	public void setKpi(KPI kpi) {
		this.kpi = kpi;
	}
	
	public StrategicGoal getStrategicGoal() {
		return strategicGoal;
	}
	
	public void setStrategicGoal(StrategicGoal strategicGoal) {
		this.strategicGoal = strategicGoal;
	}
	
	public double getWeight() {
		return weight;
	}
	
	public void setWeight(double weight) {
		this.weight = weight;
	}
	
	/**
	 * Returns goal value map as a JSONObject
	 * 
	 * @return
	 * @throws JSONException
	 */
	public JSONObject getJSON() throws JSONException {
		JSONObject json = new JSONObject();

		JSONObject kpi = getKpi().getJSON();
		JSONObject strategicGoal = getStrategicGoal().getJSON();

		json.put("weight", getWeight());
		json.put("kpi", kpi);
		json.put("strategicgoal", strategicGoal);
		json.put("goalreferencemapid", getGoalValueMapId());

		return json;
	}
}